<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<h1>项目-购物车</h1>

<script src="./utils.js"></script>
<script>
    
// 存储当前页面地址
localStorage.setItem('currentUrl',location.href)

// 获取本地存储中的token
let token = localStorage.getItem('token')

// 发送验证是否登录的请求
let xhr = new XMLHttpRequest()
xhr.open('get','http://localhost:8080/users/islogin')

// 在请求头中携带token发送到服务端
xhr.setRequestHeader('authorization',token)

xhr.send(null)

xhr.onload = function (){
    let json = JSON.parse(xhr.responseText)// 解析成JSON对象
    if (json.code == 1) {
        // 已登录，显示用户账户
        $('.box span').innerText = json.data.user
    }
}
</script>
</body>
</html>